<template>
    <div>
        <!-- 保后检查计划表:fzBhjcjhb-->
        <div class="w_100 headTips d_f j_c_s_b">
            <div class="d_f a_i_c">
                <div class="line"></div>
                {{ name }}
            </div>
            <div class="isClose" @click="close">
                <el-icon v-if="type == 'smallForm'">
                    <CloseBold />
                </el-icon>
            </div>
            <el-switch v-if="type == 'bigForm'" @change="change" v-model="status"
                style="--el-switch-on-color: #13ce66;" />
            <el-button type="primary" v-if="type == 'useForm' && isReset == 1" @click="clearForm">清除表单</el-button>
        </div>
        <div>
            <el-table :data="tableData" style="width: 100%">
                <el-table-column type="index" label="序号" width="100" fixed="left" align="center">
                    <template #default="{ $index }">
                        {{ $index + 1 }}
                    </template>
                </el-table-column>

                <el-table-column label="检查频次" prop="atPeriod">
                    <template #default="{ row }">
                        第{{ row.atPeriod }}期
                    </template>
                </el-table-column>
                <el-table-column label="开始日期" prop="checkStart" />
                <el-table-column label="到期日期" prop="checkFinish" />
                <el-table-column label="检查日期" prop="checkDate" />
                <el-table-column label="检查状态" prop="checkStatus">
                    <template #default="{ row }">
                        <span v-if="row.checkStatus == 4" class="jcerror">已过期</span>
                        <span v-if="row.checkStatus == 3" class="jcsuccess">已完成</span>
                        <span v-if="row.checkStatus == 2" class="jcpadding">检查中</span>
                        <el-button v-if="row.checkStatus == 0" size="small" type="primary"
                            :disabled="true">开始检查</el-button>
                        <el-button v-if="row.checkStatus == 1" size="small" type="primary" :disabled="row.disabled"
                            @click="startOpen(row)">开始检查</el-button>
                    </template>
                </el-table-column>
                <el-table-column type="expand">
                    <template #default="{ row, $index }">
                        <div v-if="row.checkStatus != 1">
                            <div class="w_100 headTips d_f j_c_s_b m_l_20">
                                <div class="d_f a_i_c">
                                    <div class="line"></div>
                                    保后检查计划表
                                </div>
                                <span class="edit" @click="detail(row)">查看详情</span>

                            </div>
                            <div class="w_100 headTips d_f j_c_s_b m_l_20 m_t_10">
                                <div class="d_f a_i_c">
                                    <div class="line"></div>
                                    保后检查资料上传
                                </div>
                                <!-- <span class="edit" @click="openShow(row, $index)">查看详情</span> -->

                            </div>
                            <div class="fzBhjcjhb_table">
                                <mytable :fields="fileFields" width="150" ref="tableRef"
                                    :defaultList="row.afterBusinessData" class="m_t_16" :isSelection="false"
                                    :isPaginationShow="false">
                                    <template v-slot:operation="{ row, $index }">
                                        <div class="d_f j_c_s_b">
                                            <span class="success" @click="preview(row)">预览</span>
                                        </div>
                                    </template>
                                </mytable>
                            </div>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="formBox fzBhjcjhb" v-if="show">
            <div v-if="model.plan.customerType == '1'">
                <div class="formArrow d_f a_i_c">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>自然人</span>
                </div>
                <myform :fields="fields" ref="form1" :rules="rules" :model="model.plan.personalInspect"
                    :options="options" class="m_t_16">
                </myform>
                <div class="segment"></div>
                <div class="formArrow d_f a_i_c">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>检查事项</span>
                </div>
                <div class="fzBhjcjhb_form1">
                    <myform :fields="fields1" ref="form2" :rules="rules" :model="model.plan.personalInspect"
                    :options="options" class="m_t_16">
                </myform>
                </div>
                
                <div class="segment" v-if="fields4.length > 0"></div>
                <div class="formArrow d_f a_i_c m_t_30" v-if="fields4.length > 0">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>{{ subTitle || '新加字段' }}</span>
                </div>
            </div>
            <div v-else class="fzBhjcjhb_form">
                <div class="formArrow d_f a_i_c">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>法人</span>
                </div>
                <myform :fields="fields2" ref="form1" :rules="rules1" :model="model.plan.companyInspect"
                    :options="options" class="m_t_16">
                </myform>
                <div class="segment"></div>
                <div class="formArrow d_f a_i_c">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>检查事项</span>
                </div>
                <div class="fzBhjcjhb_form2">
                    <myform :fields="fields3" ref="form2" :rules="rules1" :model="model.plan.companyInspect"
                        :options="options" class="m_t_16">
                    </myform>
                </div>
            </div>
            <div v-if="fields4.length > 0">
                <myform :fields="fields4" :model="model.plan" :options="options" class="m_t_16">
                </myform>
            </div>
        </div>
        <el-dialog v-model="dialogVisible" title="保后检查计划表" width="880px" :before-close="handleClose">
            <div class="formBox" v-if="model.plan.customerType == '1'">
                <div class="formArrow d_f a_i_c">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>自然人</span>
                </div>
                <div class="w_100 d_f j_c_c f_w_w ">
                    <div class="wid">
                        <div class="label">检查期数：</div>
                        <div class="m_l_10 value">第{{ row.period }}期</div>
                    </div>
                    <div class="wid">
                        <div class="label">检查时间：</div>
                        <div class="m_l_10 value">{{ row.checkDate || '-' }}</div>
                    </div>
                    <div class="wid  ">
                        <div class="label">检查地点：</div>
                        <div class="m_l_10 value">{{ row.checkPlace || '-' }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">检查人：</div>
                        <div class="m_l_10 value">{{ row.checker || '-' }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">检查方式：</div>
                        <div class="m_l_10 value">{{ row.checkStyle == 0 ? '现场' : '非现场' }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">是否预警：</div>
                        <div class="m_l_10 value">{{ row.isWarn == 1 ? '是' : '否' }}</div>
                    </div>
                </div>
                <div class="formArrow d_f a_i_c m_t_30">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>检查事项</span>
                </div>
                <div class="w_100 d_f j_c_c f_w_w ">
                    <div class="wid">
                        <div class="label">5级分类状态：</div>
                        <div class="m_l_10 value">{{
                            row.guaCategory == 0 ? '正常' : row.guaCategory == 1 ? '关注' : row.guaCategory == 2 ? '次级' :
                                row.guaCategory == 3 ? '可疑' : row.guaCategory == 4 ? '损失类' : '-'
                        }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">借款主要用途：</div>
                        <div class="m_l_10 value">{{ row.purpose || '-' }}</div>
                    </div>
                    <div class="wid1  ">
                        <div class="label">家庭情况：</div>
                        <div class="m_l_10 value val">{{ row.homeInfo || '-' }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">经营情况：</div>
                        <div class="m_l_10 value val">{{ row.engageInfo || '-' }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">多头贷情况：</div>
                        <div class="m_l_10 value val">{{ row.longLoanInfo || '-' }}</div>
                    </div>
                </div>

            </div>
            <div class="formBox" v-else>
                <div class="formArrow d_f a_i_c">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>法人</span>
                </div>
                <div class="w_100 d_f j_c_c f_w_w ">
                    <div class="wid">
                        <div class="label">检查期数：</div>
                        <div class="m_l_10 value">第{{ companyRow.period }}期</div>
                    </div>
                    <div class="wid">
                        <div class="label">检查时间：</div>
                        <div class="m_l_10 value">{{ companyRow.checkDate || '-' }}</div>
                    </div>
                    <div class="wid  ">
                        <div class="label">检查地点：</div>
                        <div class="m_l_10 value">{{ companyRow.checkPlace || '-' }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">检查人：</div>
                        <div class="m_l_10 value">{{ companyRow.checker || '-' }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">担保起始日期：</div>
                        <div class="m_l_10 value">{{ companyRow.checkStart || '-' }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">担保金额：</div>
                        <div class="m_l_10 value">{{ companyRow.guaMoney || '-' }}元</div>
                    </div>
                    <!-- <div class="wid">
                        <div class="label">当前担保余额：</div>
                        <div class="m_l_10 value">{{ companyRow.curGuaBalance || '-' }}元</div>
                    </div> -->
                    <div class="wid">
                        <div class="label">是否预警：</div>
                        <div class="m_l_10 value">{{ companyRow.isWarn == 1 ? '是' : '否' }}</div>
                    </div>
                    
                    <div class="wid">
                        <div class="label">五级分类状态：</div>
                        <div class="m_l_10 value">{{
                            companyRow.guaCategory == 0 ? '正常' : companyRow.guaCategory == 1 ? '关注' :
                                companyRow.guaCategory ==
                                    2 ? '次级' : companyRow.guaCategory == 3 ? '可疑' : companyRow.guaCategory == 4 ? '损失类' : '-'
                        }}</div>
                    </div>
                    <div class="wid">
                        <div class="label">配合检查人员：</div>
                        <div class="m_l_10 value">{{ companyRow.coordinateChecker || '-' }}</div>
                    </div>
                    <div class="wid"></div>
                </div>
                <div class="formArrow d_f a_i_c m_t_30">
                    <img src="../../assets/formArrow.png" alt="">
                    <span>检查事项</span>
                </div>
                <div class="w_100 d_f j_c_c f_w_w ">
                    <div class="wid1">
                        <div class="label">担保资金使用最新情况：</div>
                        <div class="m_l_10 value val">{{ companyRow.moneyLastedUse }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">合同内局限性条款执行情况：</div>
                        <div class="m_l_10 value val">{{ companyRow.contractTermsExec || '-' }}</div>
                    </div>
                    <div class="wid1  ">
                        <div class="label">非合同监控点执行情况：</div>
                        <div class="m_l_10 value val">{{ companyRow.nonContractExec || '-' }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">公司管理层情况：</div>
                        <div class="m_l_10 value val">{{ companyRow.comManage || '-' }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">经营管理情况：</div>
                        <div class="m_l_10 value val">{{ companyRow.engageInfo || '-' }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">抵质押品情况：</div>
                        <div class="m_l_10 value val">{{ companyRow.mortgageInfo || '-' }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">财务变化情况：</div>
                        <div class="m_l_10 value val">{{ companyRow.financeChange || '-' }}</div>
                    </div>
                    <div class="wid1">
                        <div class="label">检查人意见：</div>
                        <div class="m_l_10 value val">{{ companyRow.checkerRemark || '-' }}</div>
                    </div>
                </div>

            </div>
            <template #footer>
                <span class="dialog-footer">
                    <el-button type="primary" @click="handleClose">
                        关 闭
                    </el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang='ts'>
import { defineComponent, reactive, toRefs, onBeforeMount, ref } from 'vue'
import { CloseBold } from '@element-plus/icons-vue'
import { copy } from '../../utils/date'
import { NUMBRT_REG } from '../../utils/regular'
import { useRouter } from 'vue-router'
import { formGet, unitFormSet,getCheckerInfo} from '../../api/system/flowPath'
import { listByParentArr } from '../../api/login'
import { Message } from '../../utils/resetMessage'
import moment from 'moment'
import {fzBhjcjhbType} from './data'
const model = {

    currentId: '',
    plan: {
        planData: [],
        personalInspect: {
            period: '',//检查期数
            checkDate: '',//检查时间
            checkPlace: '',//检查地点
            checker: '',//检查人
            checkStyle: '',//检查方式
            isWarn: 1,//是否预警
            guaCategory: '0',//0-正常，1-关注，2-次级，3-可疑，4-代账
            purpose: '',//借款用途
            homeInfo: '',//家庭情况
            engageInfo: '',//经营情况
            longLoanInfo: '',//多头贷情况
            isReview: 1
        },
        companyInspect: {
            period: '',//检查期数
            checkDate: '',//检查时间
            checkPlace: '',//检查地点
            checker: '',//检查人
            checkStart: '',//担保起始日期
            guaMoney: '',//担保金额
            curGuaBalance: '',//当前担保余额
            isWarn: 1,//是否预警
            guaCategory: '0',//五级分类：0-正常，1-关注，2-次级，3-可疑，4-代账
            coordinateChecker: '',//配合检查人员
            moneyLastedUse: '',//担保资金使用最新情况
            contractTermsExec: '',//合同内局限性条款执行情况
            nonContractExec: '',//非合同监控点执行情况
            comManage: '',// 公司管理层情况
            engageInfo: '',//公司经营情况
            mortgageInfo: '',//质押品情况
            financeChange: '',//财务变化情况
            checkerRemark: '',//检查人意见
            isReview: 1
        },
        currentId: '',
        customerType:"1"
    },
}
export default defineComponent({
    name: '',
    props: {
        type: {
            type: String,
            default: '',
        },
        unitId: {
            type: [String, Number],
            default: '',
        },
        isEnabled: {
            type: Number,
            default: '',
        },
        nodeObj: {
            type: Object,
            default: {}
        },
        vars: {
            type: Object,
            default: {}
        },
        isAudit: {
            type: Boolean,
            default: true
        },
        projectId:{
            type: String,
            default: '' 
        }
    },
    components: {
        CloseBold
    },
    setup(props: any) {
        const data:fzBhjcjhbType = reactive({
            name: "保后检查计划表",
            period:'',
            customerType:'',
            status: true,
            model: copy(model),
            isReset: 2,
            tableData: [],
            dialogVisible: false,
            row: {},
            companyRow: {},
            options: {
                checker:[],
                isWarn: [
                    {
                        label: '是',
                        value: 1
                    },
                    {
                        label: '否',
                        value: 2
                    }
                ],
                guaCategory: [
                    {
                        label: '正常',
                        value: '0'
                    },
                    {
                        label: '关注',
                        value: '1'
                    },
                    {
                        label: '次级',
                        value: '2'
                    },
                    {
                        label: '可疑',
                        value: '3'
                    },
                    {
                        label: '损失类',
                        value: '4'
                    },
                ],
                checkStyle: [
                    {
                        name: '现场',
                        id: '0'
                    },
                    {
                        name: '非现场',
                        id: '1'
                    },
                ],
            },
            fields: [
                {
                    label: "检查期数",
                    prop: 'period',
                    placeholder: '请输入检查期数',
                    type: 'input',
                    labelWidth: '150px',
                    disabled:true,
                },
                {
                    label: "检查时间",
                    prop: 'checkDate',
                    placeholder: '请选择检查时间',
                    type: 'date',
                    labelWidth: '150px'
                },
                {
                    label: "检查地点",
                    prop: 'checkPlace',
                    placeholder: '请输入检查地点',
                    type: 'input',
                    labelWidth: '150px'
                },
                {
                    label: "检查人",
                    prop: 'checker',
                    placeholder: '请输入检查人',
                    type: 'select',
                    bindLabel: 'checker',
                    bindValue: 'checker',
                    labelWidth: '150px'
                },
                {
                    label: "检查方式",
                    prop: 'checkStyle',
                    placeholder: '请选择检查方式',
                    type: 'select',
                    bindLabel: 'name',
                    bindValue: 'id',
                    labelWidth: '150px'
                },
                {
                    label: "是否预警",
                    prop: 'isWarn',
                    placeholder: '请选择是否预警',
                    type: 'radio',
                    labelWidth: '150px'
                },
            ],
            fields1: [
                {
                    label: "五级分类状态",
                    prop: 'guaCategory',
                    placeholder: '请选择五级分类状态',
                    type: 'radio',
                    labelWidth: '150px'
                },
                {
                    label: "借款主要用途",
                    prop: 'purpose',
                    placeholder: '请输入借款主要用途',
                    type: 'input',
                    labelWidth: '150px'
                },
                {
                    label: "家庭情况",
                    prop: 'homeInfo',
                    placeholder: '请输入家庭情况',
                    type: 'textarea',
                    labelWidth: '150px'
                },

                {
                    label: "经营情况",
                    prop: 'engageInfo',
                    placeholder: '请输入经营情况',
                    type: 'textarea',
                    labelWidth: '150px'
                },
                {
                    label: "多头贷情况",
                    prop: 'longLoanInfo',
                    placeholder: '请输入多头贷情况',
                    type: 'textarea',
                    labelWidth: '150px'
                },
            ],
            rules: {
                period: [
                    { required: true, message: '请输入检查期数', trigger: 'blur' },
                    { pattern: NUMBRT_REG, message: '检查期数格式不正确' }
                ],
                checkDate: [
                    { required: true, message: '请选择检查时间', trigger: 'blur' },
                ],
                checkPlace: [
                    { required: true, message: '请输入检查地点', trigger: 'blur' },
                ],
                checker: [
                    { required: true, message: '请输入检查人', trigger: 'blur' },
                ],
                checkStyle: [
                    { required: true, message: '请选择检查方式', trigger: 'change' },
                ],
                isWarn: [
                    { required: true, message: '请选择是否预警', trigger: 'change' },
                ],
                guaCategory: [
                    { required: true, message: '请选择五级分类', trigger: 'change' },
                ],
                // purpose: [
                //     { required: true, message: '请输入借款用途', trigger: 'blur' },
                // ],
                // homeInfo: [
                //     { required: true, message: '请输入家庭情况', trigger: 'blur' },
                // ],
                // engageInfo: [
                //     { required: true, message: '请输入经营情况', trigger: 'blur' },
                // ],
                // longLoanInfo: [
                //     { required: true, message: '请输入多头贷情况', trigger: 'blur' },
                // ],
            },
            fields2: [
                {
                    label: "检查期数",
                    prop: 'period',
                    placeholder: '请输入检查期数',
                    type: 'input',
                    labelWidth: '200px',
                    disabled:true,
                },
                {
                    label: "检查时间",
                    prop: 'checkDate',
                    placeholder: '请选择检查时间',
                    type: 'date',
                    labelWidth: '200px'
                },
                {
                    label: "检查地点",
                    prop: 'checkPlace',
                    placeholder: '请输入检查地点',
                    type: 'input',
                    labelWidth: '200px'
                },
                {
                    label: "检查人",
                    prop: 'checker',
                    placeholder: '请输入检查人',
                    type: 'select',
                    bindLabel: 'checker',
                    bindValue: 'checker',
                    labelWidth: '200px'
                },
                {
                    label: "担保起始日期",
                    prop: 'checkStart',
                    placeholder: '请选择担保起始日期',
                    type: 'date',
                    labelWidth: '200px'
                },
                {
                    label: "担保金额",
                    prop: 'guaMoney',
                    placeholder: '请输入担保金额',
                    type: 'input',
                    labelWidth: '200px',
                    unit: '元'
                },
                // {
                //     label: "当前担保余额",
                //     prop: 'curGuaBalance',
                //     placeholder: '请输入当前担保余额',
                //     type: 'input',
                //     labelWidth: '200px',
                //     unit: '元'
                // },
                {
                    label: "是否预警",
                    prop: 'isWarn',
                    placeholder: '请选择是否预警',
                    type: 'radio',
                    labelWidth: '200px'
                },
                {
                    label: "五级分类状态",
                    prop: 'guaCategory',
                    placeholder: '请选择五级分类状态',
                    type: 'radio',
                    labelWidth: '200px'
                },
                {
                    label: "配合检查人员",
                    prop: 'coordinateChecker',
                    placeholder: '请输入配合检查人员',
                    type: 'input',
                    labelWidth: '200px'
                },

            ],
            fields3: [
                {
                    label: "担保资金使用最新情况",
                    prop: 'moneyLastedUse',
                    placeholder: '请输入担保资金使用最新情况',
                    type: 'textarea',
                    labelWidth: '200px'
                },
                {
                    label: "合同内局限性条款执行情况",
                    prop: 'contractTermsExec',
                    placeholder: '请输入合同内局限性条款执行情况',
                    type: 'textarea',
                    labelWidth: '200px'
                },

                {
                    label: "非合同监控点执行情况",
                    prop: 'nonContractExec',
                    placeholder: '请输入非合同监控点执行情况',
                    type: 'textarea',
                    labelWidth: '200px'
                },
                {
                    label: "公司管理层情况",
                    prop: 'comManage',
                    placeholder: '请输入公司管理层情况',
                    type: 'textarea',
                    labelWidth: '200px'
                },
                {
                    label: "经营管理情况",
                    prop: 'engageInfo',
                    placeholder: '请输入经营管理情况',
                    type: 'textarea',
                    labelWidth: '200px'
                },
                {
                    label: "抵质押品情况",
                    prop: 'mortgageInfo',
                    placeholder: '请输入抵质押品情况',
                    type: 'textarea',
                    labelWidth: '200px'
                },
                {
                    label: "财务变化情况",
                    prop: 'financeChange',
                    placeholder: '请输入财务变化情况',
                    type: 'textarea',
                    labelWidth: '200px'
                },
                {
                    label: "检查人意见",
                    prop: 'checkerRemark',
                    placeholder: '请输入检查人意见',
                    type: 'textarea',
                    labelWidth: '200px'
                },
            ],
            rules1: {
                period: [
                    { required: true, message: '请输入检查期数', trigger: 'blur' },
                    { pattern: NUMBRT_REG, message: '检查期数格式不正确' }
                ],
                checkDate: [
                    { required: true, message: '请选择检查时间', trigger: 'change' },
                ],
                checkPlace: [
                    { required: true, message: '请输入检查地点', trigger: 'blur' },
                ],
                checker: [
                    { required: true, message: '请输入检查人', trigger: 'blur' },
                ],
                checkStart: [
                    { required: true, message: '请输入担保起始日期', trigger: 'blur' },
                ],
                guaMoney: [
                    { required: true, message: '请输入担保金额', trigger: 'blur' },
                    { pattern: NUMBRT_REG, message: '担保金额格式不正确' }
                ],
                curGuaBalance: [
                    { required: true, message: '请输入当前担保余额', trigger: 'blur' },
                    { pattern: NUMBRT_REG, message: '当前担保余额格式不正确' }
                ],
                isWarn: [
                    { required: true, message: '请选择是否预警', trigger: 'change' },
                ],
                guaCategory: [
                    { required: true, message: '请选择五级分类', trigger: 'change' },
                ],
                coordinateChecker: [
                    { required: true, message: '请输入配合检查人员', trigger: 'blur' },
                ],


                // moneyLastedUse: [
                //     { required: true, message: '请输入担保资金使用最新情况', trigger: 'blur' },
                // ],
                // contractTermsExec: [
                //     { required: true, message: '请输入合同内局限性条款执行情况', trigger: 'blur' },
                // ],
                // nonContractExec: [
                //     { required: true, message: '请输入非合同监控点执行情况', trigger: 'blur' },
                // ],
                // comManage: [
                //     { required: true, message: '请输入公司管理层情况', trigger: 'blur' },
                // ],
                // engageInfo: [
                //     { required: true, message: '请输入经营管理情况', trigger: 'blur' },
                // ],
                // mortgageInfo: [
                //     { required: true, message: '请输入抵质押品情况', trigger: 'blur' },
                // ],
                // financeChange: [
                //     { required: true, message: '请输入财务变化情况', trigger: 'blur' },
                // ],
                // checkerRemark: [
                //     { required: true, message: '请输入检查人意见', trigger: 'blur' },
                // ],
            },
            fields4: [],
            id: '',
            subTitle: '',
            show: false,
            fileFields: [
                {
                    label: '资料名称',
                    prop: 'businessDataName',
                },
                {
                    label: '上传环节',
                    prop: 'nodeName',
                },
                {
                    label: '上传人',
                    prop: 'uploadName',
                },
                {
                    label: '上传时间',
                    prop: 'uploadTime',
                },
            ],
            ischeck: false,
            isForm: false,
            isError: false,
        })
        const router = useRouter()
        const form1 = ref()
        const form2 = ref()
        onBeforeMount(() => {
            methods.getData()
            data.status = props.isEnabled == 0 ? false : true
        })
        const methods = {
            close() {
                router.push('/system/flowPath/childForm/index')
            },
            getData() {
                getCheckerInfo({projectId:props.projectId}).then((res:any)=>{
                   data.options.checker=res
                })
                formGet({ tag: 'fzBhjcjhb' }).then((res: any) => {
                    data.id = res.id
                    data.name = res.name
                    data.isReset = res.isReset
                    if (!res.formStruct || res.formStruct == 'null' || res.formStruct == '{}') return
                    data.subTitle = res.subTitle
                    let formStruct = JSON.parse(res.formStruct)
                    formStruct.formFields.map((item: any) => {
                        data.model.plan[item.prop] = ''
                    })
                    data.fields4 = formStruct.formFields
                    if (props.vars) {
                        const localData = props.vars
                        for (let key in data.model.plan) {
                            if(localData.plan[key]!=null){
                                data.model.plan[key] = localData.plan[key]
                            }
                        }
                        if (localData.plan.companyInspect) {
                            data.model.plan.companyInspect = localData.plan.companyInspect
                        } else {
                            data.model.plan.companyInspect = {
                                period: '',//检查期数
                                checkDate: '',//检查时间
                                checkPlace: '',//检查地点
                                checker: '',//检查人
                                checkStart: '',//担保起始日期
                                guaMoney: '',//担保金额
                                curGuaBalance: '',//当前担保余额
                                isWarn: 1,//是否预警
                                guaCategory: '0',//五级分类：0-正常，1-关注，2-次级，3-可疑，4-代账
                                coordinateChecker: '',//配合检查人员
                                moneyLastedUse: '',//担保资金使用最新情况
                                contractTermsExec: '',//合同内局限性条款执行情况
                                nonContractExec: '',//非合同监控点执行情况
                                comManage: '',// 公司管理层情况
                                engageInfo: '',//公司经营情况
                                mortgageInfo: '',//质押品情况
                                financeChange: '',//财务变化情况
                                checkerRemark: '',//检查人意见
                                isReview: 1
                            }
                        }
                        if (localData.plan.personalInspect) {
                            data.model.plan.personalInspect = localData.plan.personalInspect
                        } else {
                            data.model.plan.personalInspect = {
                                period: '',//检查期数
                                checkDate: '',//检查时间
                                checkPlace: '',//检查地点
                                checker: '',//检查人
                                checkStyle: '',//检查方式
                                isWarn: 1,//是否预警
                                guaCategory: '0',//0-正常，1-关注，2-次级，3-可疑，4-代账
                                purpose: '',//借款用途
                                homeInfo: '',//家庭情况
                                engageInfo: '',//经营情况
                                longLoanInfo: '',//多头贷情况
                                companyInspect:'',
                                isReview: 1
                            }
                        }
                        data.model.plan.customerType = localData.plan.customerType
                        data.customerType=localData.plan.customerType
                        if (data.model.plan.personalInspect.guaCategory != null) {
                            data.model.plan.personalInspect.guaCategory = String(data.model.plan.personalInspect.guaCategory)
                        }
                        if (data.model.plan.personalInspect.companyInspect != null) {
                            data.model.plan.personalInspect.companyInspect = String(data.model.plan.personalInspect.companyInspect)
                        }
                        if (data.model.plan.personalInspect.checkStyle != null) {
                            data.model.plan.personalInspect.checkStyle = String(data.model.plan.personalInspect.checkStyle)
                        }
                        props.vars.plan.planData.map(item => {
                            item.show = false
                        })
                        data.tableData = props.vars.plan.planData
                        let day = moment(new Date()).format('YYYY-MM-DD')
                        data.tableData.map((item: any) => {
                            let start = moment(day+' 00:00:00').diff(item.checkStart+' 00:00:00', 'days')
                            let end = moment(day+' 23:59:59').diff(item.checkFinish+' 23:59:59', 'days')
                            console.log(start,end);
                            if (end > 0&&item.checkStatus!=3&&item.checkStatus!=2) {
                                item.checkStatus = 4
                            }
                            if (start < 0) {
                                item.checkStatus = 0
                            }
                            if(start>=0&&end<0&&item.checkStatus!=2&&item.checkStatus!=3){
                                item.checkStatus = 1
                            }
                        })
                        data.isError = data.tableData.every((item: any) => item.checkStatus == 4)
                        data.ischeck = data.tableData.some((item: any) => item.checkStatus == 1)
                        data.isForm = data.tableData.some((item: any) => item.checkStatus == 0)
                        console.log(data.ischeck);

                    }
                    let arr = formStruct.formFields.filter((item: any) => {
                        return item.type == 'select'
                    })
                    let ids = arr.map((item: any) => {
                        return item.prop
                    })
                    if (ids.length == 0) return
                    listByParentArr({ ids: ids }).then((res: any) => {
                        ids.map((item: any) => {
                            data.options[item] = res[item]
                        })
                    })
                })
            },
            //预览文件
            preview(row: any) {
                window.open(row.fileUrl, '_blank')
            },
            //设置表单的启用跟停用
            change() {
                unitFormSet({ isEnabled: data.status ? 1 : 0, id: data.id, unitId: props.unitId }).then(() => {
                    Message({ type: 'success', message: '设置成功' })
                }).catch(() => {
                    data.status = !data.status
                })
            },
            openShow(row: any, index: number) {
                // data.tableData[index].show1 = !row.show1
            },
            //回调
            resultData() {
                // if (data.isError) return Message({ type: 'error', message: '没有可以开始检查的频次' })
                data.model.plan.planData = data.tableData
                return new Promise((resolve, reject) => {
                    if (!data.ischeck&&!data.isError) return Message({ type: 'error', message: '未到检查时间' })
                    if (data.ischeck) {
                       if(!form1.value)return Message({ type: 'error', message: '请先开启检查' })
                        form1.value.verification().then((res) => {
                           
                            console.log(res);
                            form2.value.verification().then((res) => {
                                resolve(data.model)
                            }).catch(() => {
                                reject('fzBhjcjhb')
                            })
                        }).catch(() => {
                            reject('fzBhjcjhb')
                        })
                    } else {
                        
                        resolve({ customerType: data.model.plan.customerType, plan: { planData: data.tableData,customerType: data.model.plan.customerType, } })
                    }

                })
            },
            saveData() {
                return new Promise((resolve, reject) => {
                    resolve(data.model)
                })
            },
            //清除表单数据
            clearForm() {
                data.model = copy(model)
                data.model.plan.customerType=data.customerType
                if(data.customerType=='1'){
                    data.model.plan.personalInspect.period=data.period
                }else{
                    data.model.plan.companyInspect.period=data.period
                }
            },
            //查看保后检查计划表信息
            detail(row: any) {
                if (!row.detail) return Message({ type: 'error', message: '暂无保后信息' })
                if (data.model.plan.customerType == '1') {
                    if (!row.detail.personalInspect) return Message({ type: 'error', message: '暂无保后信息' })
                    data.row = row.detail.personalInspect
                } else {
                    if (!row.detail.companyInspect) return Message({ type: 'error', message: '暂无保后信息' })
                    data.companyRow = row.detail.companyInspect
                    data.companyRow.checkStart = moment(data.companyRow.checkStart).format('YYYY-MM-DD')
                }

                data.dialogVisible = true
            },
            handleClose() {
                data.dialogVisible = false
            },
            startOpen(row: any) {
                data.model.currentId = row.id
                data.model.plan.currentId = row.id
                if(data.model.plan.customerType=='1'){
                    data.model.plan.personalInspect.period=row.atPeriod
                }else{
                    data.model.plan.companyInspect.period=row.atPeriod
                }
                data.period=row.atPeriod
                data.isForm = true
                if (props.isAudit) return
                data.show = true
            }
        }
        return {
            ...toRefs(data),
            ...methods, form1, form2
        }
    }
})
</script>
<style scoped lang='scss'>
.wid {
    width: 380px;
    color: #000000;
    font-size: 14px;
    margin-top: 20px;
    display: flex;
}
.value {
        width: 215px;
        word-wrap: break-word;
        /* 允许在单词内换行 */
        overflow-wrap: break-word;
        /* 同上，现代浏览器推荐使用这个属性别名 */
        white-space: normal;
        /* 允许自动换行 */
    }
.label {
        text-align: right;
        width: 190px;
    }
    .val{
        width: calc(100% - 185px) !important;
    } 
.wid1{
    width: 100%;
    color: #000000;
    font-size: 14px;
    margin-top: 20px;
    display: flex;
}
.jcerror {
    color: #F89898;
}

.jcsuccess {
    color: #00B42A;
}

.jcpadding {
    color: #409EFF;
}
</style>
<style lang='scss'>
.fzBhjcjhb_table {
    margin-left: 20px;
    width: calc(100% - 50px);

    .el-table {
        width: 100% !important;
    }
}

.fzBhjcjhb {
    .el-form-item {
        width: 50% !important;
        margin-right: 0px !important;

        .el-form-item__content {
            width: calc(100% - 150px) !important;

            .el-input,
            .el-cascader,
            .el-select {
                width: 100% !important;
            }
        }
    }
}

.fzBhjcjhb_form {
    // .el-form-item:nth-child(9) {
    //     width: 100% !important;
    // }
}
.fzBhjcjhb_form1{
     .el-form-item:nth-child(3), .el-form-item:nth-child(4), .el-form-item:nth-child(5) {
        width: 100% !important;
    }
}
.fzBhjcjhb_form2{
    .el-form-item {
        width: 100% !important;
    }
}
</style>